import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../../res/HDColors.dart';
import '../../../../view/FieldEditor.dart';
import '../../../../view/common_widget.dart';
import '../../../../view/image_picker_widget.dart';
import 'logic.dart';

class OperationDetailPage extends StatelessWidget {
  final logic = Get.put(OperationDetailLogic());
  final state = Get.find<OperationDetailLogic>().state;

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        onWillPop: () async {
          logic.closePage();
          return false;
        },
        child: Scaffold(
            appBar: AppBar(
                title: const Text("运维详情"),
                elevation: 0,
                backgroundColor: HDColors.green,
                leading: CommonWidget.getAppBarLeading()),
            body: GetBuilder<OperationDetailLogic>(builder: (logic) {
              return SingleChildScrollView(
                physics: ClampingScrollPhysics(),
                child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      FieldEditor(
                        label: '客户姓名',
                        hintText: '请输入客户姓名',
                        contentTextAlign: TextAlign.end,
                        initialValue: state.operationBean.customerName ?? "",
                        showLine: false,

                        readOnly: true,
                      ),
                      FieldEditor(
                        label: '客户电话',
                        hintText: '请输入客户手机号',
                        contentTextAlign: TextAlign.end,
                        showLine: false,

                        readOnly: true,
                        initialValue: state.operationBean.phoneNumber,
                      ),
                      FieldEditor(
                        label: '建站地址',
                        hintText: '请输入建站地址',
                        contentTextAlign: TextAlign.end,
                        showLine: false,

                        readOnly: true,
                        initialValue: state.operationBean.buildingAddress,
                      ),
                      FieldEditor(
                        label: '踏勘位置',
                        hintText: '请输入踏勘位置',
                        contentTextAlign: TextAlign.end,
                        showLine: false,

                        readOnly: true,
                        initialValue: state.operationBean.address,
                      ),
                      FieldEditor(
                        label: '故障说明',
                        hintText: '请输入踏勘位置',
                        contentTextAlign: TextAlign.end,
                        showLine: false,

                        readOnly: true,
                        initialValue: state.operationBean.faultDescription,
                      ),
                      Container(
                        margin: const EdgeInsets.fromLTRB(13, 0, 20, 0),
                        child: Text('维修前照片',
                            style:
                                TextStyle(color: HDColors.black, fontSize: 16)),
                      ),
                      Container(
                        margin: const EdgeInsets.fromLTRB(13, 10, 20, 0),
                        child: ImagePickerWidget(
                            readonly: state.isReadOnly,
                            controller: state.beforeController),
                      ),
                      Container(
                        margin: const EdgeInsets.fromLTRB(13, 10, 20, 0),
                        child: Text('维修中照片',
                            style:
                                TextStyle(color: HDColors.black, fontSize: 16)),
                      ),
                      Container(
                        margin: const EdgeInsets.fromLTRB(13, 10, 20, 0),
                        child: ImagePickerWidget(
                            readonly: state.isReadOnly,
                            controller: state.repairInController),
                      ),
                      Container(
                        margin: const EdgeInsets.fromLTRB(13, 0, 20, 0),
                        child: Text('维修后照片',
                            style:
                                TextStyle(color: HDColors.black, fontSize: 16)),
                      ),
                      Container(
                        margin: const EdgeInsets.fromLTRB(13, 10, 20, 0),
                        child: ImagePickerWidget(
                            readonly: state.isReadOnly,
                            controller: state.afterController),
                      ),
                      FieldEditor(
                        label: '维修描述:',
                        hintText: '请在下方填写维修描述',
                        contentTextAlign: TextAlign.end,
                        showLine: true,
                        isRequired: false,
                      ),
                      BrnInputText(
                        maxHeight: 500,
                        minHeight: 40,
                        maxLength: 500,
                        autoFocus: false,
                        bgColor: Colors.grey[200]!,
                        textInputAction: TextInputAction.newline,
                        maxHintLines: 200,
                        textString: state.operationBean.described ?? "请输入维修描述",
                        hint: '请输入维修描述',
                        padding: EdgeInsets.fromLTRB(15, 10, 20, 14),
                        onTextChange: (text) {
                          state.operationBean.described = text;
                        },
                      ),
                      Visibility(
                          visible: !state.isReadOnly, child: getFooterButton())
                    ]),
              );
            })));
  }

  getFooterButton() {
    return Container(
        decoration: const BoxDecoration(color: HDColors.white, boxShadow: [
          BoxShadow(
              color: HDColors.grayBg,
              offset: Offset(0, -2),
              blurRadius: 8,
              spreadRadius: 1)
        ]),
        padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 10),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            CommonWidget.buildBottomBtn("保存", () {
              logic.submit(0);
            }),
            CommonWidget.buildBottomBtn("结束运维", () {
              logic.submit(1);
            }),
          ],
        ));
  }
}
